package com.ruoyi.web.controller.api;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.api.domain.ProjectApi;
import com.ruoyi.api.service.IProjectApiService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 接口管理Controller
 *
 * @author yhg
 * @date 2022-10-21
 */
@RestController
@RequestMapping("/api/api")
public class ProjectApiController extends BaseController
{
    @Autowired
    private IProjectApiService projectApiService;

    /**
     * 查询接口管理列表
     */
    @PreAuthorize("@ss.hasPermi('api:api:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProjectApi projectApi)
    {
        startPage();
        List<ProjectApi> list = projectApiService.selectProjectApiList(projectApi);
        return getDataTable(list);
    }

    /**
     * 导出接口管理列表
     */
    @PreAuthorize("@ss.hasPermi('api:api:export')")
    @Log(title = "接口管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProjectApi projectApi)
    {
        List<ProjectApi> list = projectApiService.selectProjectApiList(projectApi);
        ExcelUtil<ProjectApi> util = new ExcelUtil<ProjectApi>(ProjectApi.class);
        util.exportExcel(response, list, "接口管理数据");
    }

    /**
     * 获取接口管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('api:api:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(projectApiService.selectProjectApiById(id));
    }

    /**
     * 新增接口管理
     */
    @PreAuthorize("@ss.hasPermi('api:api:add')")
    @Log(title = "接口管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProjectApi projectApi)
    {
        return toAjax(projectApiService.insertProjectApi(projectApi));
    }

    /**
     * 修改接口管理
     */
    @PreAuthorize("@ss.hasPermi('api:api:edit')")
    @Log(title = "接口管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProjectApi projectApi)
    {
        return toAjax(projectApiService.updateProjectApi(projectApi));
    }

    /**
     * 删除接口管理
     */
    @PreAuthorize("@ss.hasPermi('api:api:remove')")
    @Log(title = "接口管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(projectApiService.deleteProjectApiByIds(ids));
    }
}
